﻿
@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<link href="~/Content/js/dialog/dialog.css" rel="stylesheet" />
<script src="~/Content/js/dayin/jquery.jqprint-0.3.js"></script>
<script>
    var keyValue = $.request("keyValue");
    var fidList = new Array();
    var pathwayName = decodeURI(keyValue);
    $(function () {
        gridList();
        if (!!pathwayName) {
            var str = "";
            str += "<span>" + pathwayName + "</span>";
            $("#PathwayName").append(str);
        }
        
    });
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/Project/GudaoCar/GetGridJsonGudaoCar",
            postData: { keyValue: keyValue },
            rownumbers: false,
            height: $(window).height() - 96,
            colModel: [
                { label: "主键", name: "F_Id", hidden: true, key: true },
                {
                    label: '序号', name: 'CarGudaoIndex', width: 30, align: 'center',
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue != null ? cellvalue : "未填写";
                    }
                },
                {
                    label: '车号', name: 'BelongCarriage', width: 60, align: 'left',
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue != null ? cellvalue.CarriageID : "未填写";
                    }
                   
                },
                {
                    label: '车型', name: 'BelongCarriage', width: 40, align: 'left',
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue != null ? cellvalue.CarType : " ";
                    }
                },
                {
                    label: '品名', name: 'ThingsName', width: 50, align: 'left',
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue != null ? cellvalue : " ";
                    }
                },
                {
                    label: '封号', name: 'Fenhao', width: 85, align: 'left',
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue != null ? cellvalue : " ";
                    }
                },
                {
                    label: '到站', name: 'ArriveStation', width: 80, align: 'left',
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue != null ? cellvalue : " ";
                    }
                },
                {
                    label: '件数', name: 'UnitNumber', width: 40, align: 'left',
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue != null ? cellvalue : "0";
                    }
                },
                {
                    label: '重量（吨）', name: 'Weight', width: 60, align: 'left',
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue != null ? cellvalue : "0";
                    }
                },
                {
                    label: '箱号', name: 'CarBoxStr', width: 60, align: 'left',
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue != null ? cellvalue : "暂无";
                    }
                },
                
                {
                    label: '客户', name: 'Customers', width: 70, align: 'left'
                },
                //{
                //    label: '箱号', name: 'isQiPiao', width: 150, align: 'left', cellattr:addCellAttr,
                //    formatter: function (cellvalue) {
                //        return "111111111111111111111111111111,2222222222";
                //    }
                //},
                {
                    label: '是否起票', name: 'isQiPiao', width: 50, align: 'left', cellattr:addCellAttr,
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue == true ? "已起票" : "未起票";
                    }
                },
                {
                    label: '统计运量', name: 'isAccomplishStatistics', width: 50, align: 'left', cellattr: addCellAttr,
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue == true ? "已统计" : "未统计";
                    }
                },
                {
                    label: '是否对位', name: 'IsAccomplishduiwei', width: 50, align: 'left', cellattr: addCellAttr,
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue == true ? "已对位" : "未对位";
                    }
                },
                {
                    label: '是否放行', name: 'IsAccomplishPermitThrough', width: 50, align: 'left', cellattr: addCellAttr,
                    formatter: function (cellvalue) {
                        debugger;
                        return cellvalue == true ? "已放行" : "未放行";
                    }
                },  
                {
                    label: '备注', name: 'Remark', width: 100, align: 'center'
                },
                {
                    label: ' 操作', name: 'F_Id', index: 'operate', width: 360, align: 'center',
                    formatter: function (value, row, index) {
                        //alert(value);
                        //console.log(value);
                        //var detail=
                        //    "<input type=\"button\" onclick='QiPiao(name)' style=\"margin-right:10px\" name=" + value + " value=\"起票\"/>" +

                        //    "<input type=\"button\" onclick=\"Statistic()\" style=\"margin-right:10px\" value=\"统计\"/>" +
                        //    "<input type=\"button\" onclick=\"CancelStatistic()\" style=\"margin-right:10px\" value=\"取消统计\"/>" +
                        //     "<input type=\"button\" onclick=\"FangXing()\" style=\"margin-right:10px\" value=\"放行\"/>";
                        var result = "";
                        if (index.isQiPiao == true) {
                            result +=
                                "<input type=\"button\" onclick='CancelQiPiao(name)' style=\"margin-right:5px; width:50px\" name=" +
                                value +
                                " value=\"取消起票\"/>";
                        } else {
                            result +=
                                "<input type=\"button\" onclick='QiPiao(name)' style=\"margin-right:5px; width:50px\" name=" +
                                value +
                                " value=\"起票\"/>";
                        }

                        if (index.isAccomplishStatistics == true) {
                            result +=
                                "<input type=\"button\" onclick='CancelStatistic(name)' style=\"margin-right:5px; width:50px\" name=" +
                                value +
                                " value=\"取消统计\"/>";
                        } else {
                            result +=
                                "<input type=\"button\" onclick='Statistic(name)' style=\"margin-right:5px; width:50px\" name=" +
                                value +
                                " value=\"统计\"/>";
                        }

                        if (index.IsAccomplishPermitThrough == true) {
                            result +=
                                "<input type=\"button\" onclick='CancelFangXing(name)' style=\"margin-right:5px; width:50px\" name=" +
                                value +
                                " value=\"取消放行\"/>";
                        } else {
                            result +=
                                "<input type=\"button\" onclick='FangXing(name)' style=\"margin-right:5px; width:50px\" name=" +
                                value +
                                " value=\"放行\"/>";
                        }
                        if (index.BelongPathway.IsCounterpoint == true) {
                            if (index.IsAccomplishduiwei == true) {
                                result +=
                                    "<input type=\"button\" onclick='CancelDuiwei(name)' style=\"margin-right:5px; width:50px\" name=" +
                                    value +
                                    " value=\"取消对位\"/>";
                            } else {
                                result +=
                                    "<input type=\"button\" onclick='Duiwei(name)' style=\"margin-right:5px; width:50px\" name=" +
                                    value +
                                    " value=\"对位\"/>";
                            }
                           
                        }
                        result += "<input type=\"button\" onclick='ModifyInfo(name)' style=\"margin-right:5px; width:50px\" name=" +
                            value + " value=\"修改\"/>";
                        result += "<input type=\"button\" onclick='BoxInfo(name)' style=\"margin-right:5px; width:50px\" name=" +
                            value + " value=\"箱号操作\"/>";
                        return result;
                    }
                },
                {
                    label: '达到日期', name: 'ArriveDateTime', width: 130, align: 'center'
                }

            ],
            pager: "#gridPager",
            sortname: 'CarGudaoIndex desc',
            viewrecords: true

        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: {
                    keyword: $("#txt_keyword").val(),
                    name: $("#txt_name").val()
                },
            }).trigger('reloadGrid');
        });
    }

    function addCellAttr(rowId, val, rawObject, cm, rdata) {
        
        //console.log('rowId:'+rowId);
        //console.log('rawObject:' + rawObject);
        //console.log('cm:' + cm);
        //console.log('rdata:' + rdata);
        if (val == "已起票"||val=="已统计"||val=="已放行"||val=="已对位") {
            return "style='color:green'";
        } else {
            return "style='color:red'";
        }
       
    }
   
    function QiPiao(fid) {
        if (!!fid) {
            $.modalConfirm("注：您确定要起票吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/Project/GudaoCar/QiPiao",
                        param: { keyValue: fid },
                        close: false,
                        success: function () {
                            //$.currentWindow().$("#gridList").trigger("reloadGrid");
                            //$.reload();
                            alert("起票成功");
                        }
                    });
                }
            });

        }
    };
    function CancelQiPiao(fid) { 
        if (!!fid) {
            $.modalConfirm("注：您确定要撤销起票吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/Project/GudaoCar/CancelQiPiao",
                        param: { keyValue: fid },
                        close: false,
                        success: function () {
                            //$.currentWindow().$("#gridList").trigger("reloadGrid");
                            //$.reload();
                            alert("撤销起票成功");
                        }
                    });
                }
            });

        }

    };
    function Statistic(fid) {
        if (!!fid) {
            $.modalConfirm("注：您确定要统计运量吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/Project/GudaoCar/Statistic",
                        param: { keyValue: fid },
                        close:false,
                        success: function() {
                            //$.currentWindow().$("#gridList").trigger("reloadGrid");
                            //$.reload();
                            alert("运量统计成功");
                        }
                    });
                }
            });

        }
    }
    function BoxInfo(fId) {
        if (!!fId) {
            $.modalOpen({
                id: "SelectCarBox",
                title: "选择选择添加箱号",
                url: "/Project/CarriageBox/AddBoxToCar?keyVaules=" + fId,
                width: "600px",
                height: "450px",
                callBack: function(iframeId) {
                    top.frames[iframeId].SubmitThisInfo();
                }
            });
        }
    }

    function CancelStatistic(fid) {
        if (!!fid) {
            $.modalConfirm("注：您确定要取消统计运量吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/Project/GudaoCar/CancelStatistic",
                        param: { keyValue: fid },
                        close: false,
                        success: function () {
                           // $.reload();
                            alert("撤销运量统计成功");
                        }
                    });
                }
            });

        }
    }

    function FangXing(fid) {
        if (!!fid) {
            $.modalOpen({
                id: "SelectPer",
                title: "选择放行人员",
                url: encodeURI("/Project/GudaoCar/SelectPer?keyValue=" + fid),
                width: "240px",
                height: "240px",
                callBack: function(iframeId) {
                    top.frames[iframeId].submitForm();
                    setTimeout(function() {
                            $("#loadingPage").css("display", "none");
                            $("#gridList").children().empty();
                            $.reload();
                            gridList();
                        //alert("放行成功");
                        },
                        700);
                }

        });

        }
    }
    function CancelFangXing(fid) {
        $.modalConfirm("注：您确定要取消放行吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/Project/GudaoCar/CancelPass",
                    param: { keyValue: fid },
                    close: false,
                    success: function () {
                        $.reload();
                        alert("取消放行成功");
                    }
                });
            }
        });
    }

    function Duiwei(fid) {
        if (!!fid) {
            $.modalConfirm("注：您确定要对位吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/Project/GudaoCar/Duiwei",
                        param: { keyValue: fid },
                        close: false,
                        success: function () {
                            //$.currentWindow().$("#gridList").trigger("reloadGrid");
                            //$.reload();
                            alert("对位成功");
                        }
                    });
                }
            });

        }
    }

    function CancelDuiwei(fid) {
        if (!!fid) {
            $.modalConfirm("注：您确定要取消对位吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/Project/GudaoCar/CancelDuiwei",
                        param: { keyValue: fid },
                        close: false,
                        success: function () {
                            //$.reload();
                            alert("取消对位成功");
                        }
                    });
                }
            });

        }
    }
    function ModifyInfo(fid) {
       // alert("修改信息：" + fid);
        //var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Form",
            title: "修改车辆信息",
            url: "/Project/Pathway/Edit?keyValue=" + fid,
            width: "520px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
                setTimeout(function () {
                        //$("#loadingPage").css("display", "none");
                        //$("#gridList").children().empty();
                        $.reload();
                        //gridList();
                    },
                   1000);
            }
        });
    }
    function btn_state() {
        debugger;
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
       
    }

    function preview() {
        $("#gview_gridList").jqprint({
            debug: false,
            importCSS: false,//只显示文本内容设为false
            printContainer: true,
            operaSupport: true
        });
    }

</script>


<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <div style="float: left;width:100px" id="PathwayName" class="btn btn-primary" onclick="$.reload()">
            </div>
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            <button class="btn dayin" style="width: 20px!important;height: 22px!important" onclick="preview()"></button>
        </div>
        <div class="btn-group">
            @*<a id="NF-add" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新增股道</a>*@
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
               
                @*<li class="first">已选中<span>1</span>项</li>
                    <li><a id="NF-edit" onclick="QiPiao()"><i class="fa fa-pencil-square-o"></i>起票</a></li>
                    <li><a id="NF-delete" onclick="Statistic()"><i class="fa fa-trash-o"></i>统计运量</a></li>
                    <li><a id="NF-Details" onclick="CancelStatistic()"><i class="fa fa-search-plus"></i>取消统计运量</a></li>
                    <li><a id="NF-Details" onclick="FangXing()"><i class="fa fa-search-plus"></i>放行</a></li>*@
                <li class="split"></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group" style="padding-left:11px;padding-right:10px;">
                        @*<input id="txt_keyword" type="text" class="form-control" placeholder="按照课程名称模糊搜索" style="width: 200px; margin-right:20px;">*@
                        @*<select id="txt_state" class="form-control" style="width: 120px;margin-right:20px;" placeholder="按照状态搜索">
                                <option value="">请选择</option>
                                <option value="0">未审核</option>
                                <option value="1">审核驳回</option>
                                <option value="2">审核中</option>
                                <option value="3">审核通过</option>

                            </select>*@
                        @*<input id="txt_name" type="text" class="form-control" placeholder="按照场主名称模糊搜索" style="width: 200px; margin-right:20px;">
                            <span class="input-group-btn">
                                <button id="btn_search" type="button" class="btn  btn-primary active"><i class="fa fa-search"></i></button>
                            </span>*@
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>


<style>
    table tr td {
        padding-left: 15px;
    }
    .ui-jqgrid tr.jqgrow {
        border: 1px gray solid;
    }
    .ui-jqgrid tr.jqgrow td {
        border: 1px gray solid;
    }
    .dayin {
        background: url('../../../../Content/js/dayin/dayin.jpg') no-repeat;
        background-size: 100% 100%;
        border-style:none; 
        width:35px!important;
        height: 32px !important;
        margin-left:17px!important;
    }
    .dayin:hover {
        background: url('../../../../Content/js/dayin/dayin.jpg') no-repeat;
        background-size: 100% 100%;
        border-style:none; 
        width:35px!important;
        height: 32px !important;
        margin-left:17px!important;
    }
</style>
<div class="gridPanel">
    <table id="gridList" style="border:1px yellow solid "></table>
    <div id="gridPager"></div>
</div>


